﻿using UnityEngine;
using System.Collections;
using ProtoBuf.Message;

namespace UI
{
    public delegate void EventHandler();
    public class UIHeroEvent :MonoBehaviour
    {
        public EventHandler switchHeroHandler;
        public EventHandler uploadHeroHandler;

        public void OnMaskClick()
        {
            gameObject.GetComponent<UIHeroPage>().Close();
        }

        public void OnCloseClick()
        {
            gameObject.GetComponent<UIHeroPage>().Close();
        }

        //突破按钮
        public void OnBreachClick()
        {
            //检测等级
            if (StaticData.playerData.level < Dict.DictDataManager.Instance.tableGameConfigureDao.currentData.HeroBreachedLevel)
            {
                BoxManager.CreatePopupTextBox(string.Format(TableTextBlo.GetText("hero_breach_level_limit"), Dict.DictDataManager.Instance.tableGameConfigureDao.currentData.HeroBreachedLevel));
                return;
            }
            gameObject.GetComponent<UIHeroPage>().Close();
            PageManager.Instance.OpenPage("characterRemotePage", "guid=" + gameObject.GetComponent<UIHeroLogic>().hero.guid + "&tab=3");
        }

        //升级
        public void OnLevelUpClick()
        {
            gameObject.GetComponent<UIHeroPage>().Close();
            PageManager.Instance.OpenPage("characterRemotePage", "guid=" + gameObject.GetComponent<UIHeroLogic>().hero.guid + "&tab=0");
        }

        //天赋
        public void OnTalentClick()
        {
            gameObject.GetComponent<UIHeroPage>().Close();
            PageManager.Instance.OpenPage("characterRemotePage", "guid=" + gameObject.GetComponent<UIHeroLogic>().hero.guid + "&tab=1");
        }

        //训练
        public void OnTrainingClick()
        {
            gameObject.GetComponent<UIHeroPage>().Close();
            PageManager.Instance.OpenPage("characterRemotePage", "guid=" + gameObject.GetComponent<UIHeroLogic>().hero.guid + "&tab=2");
        }

        /// <summary>
        /// 交换英雄
        /// </summary>
        public void OnSwitchHeroClick()
        {
            if(switchHeroHandler!=null)
            {
                GetComponent<UIHeroPage>().Close();
                switchHeroHandler();
            }
        }

        /// <summary>
        /// 卸载英雄
        /// </summary>
        public void OnUnloadHeroClick()
        {
            if (uploadHeroHandler != null)
            {
                //GetComponent<UIHeroPage>().Close();
                uploadHeroHandler();
            }
        }
    }
}